package com.lj.universalframework.app

import android.app.Activity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.lj.universalframework.BR
import com.lj.universalframework.base.PageJumpBase

abstract class BaseViewModel :ViewModel(),ViewModelLifecycle{

    companion object {
        const val SOCKET = "java.net.SocketTimeoutException: connect timed out"
        const val CONNECT = "java.net.ConnectException:"
        const val SOCKETTIME = "java.net.SocketTimeoutException: failed to connect to"
    }

    private var lifcycleOwner: LifecycleOwner? = null

    // loading视图显示Event
    var _loadingEvent = MutableLiveData<Boolean>()
    //当前状态 0---》加载中 1---》网络不通 2---》网络通了，但请求异常 3---》网络通，但请求无数据  4--》
    var loadingStatus = MutableLiveData(0)
    //下拉刷新状态
    var pullDownRefresh = MutableLiveData(false)
    //上拉加载
    var pullUpLoading = MutableLiveData(false)
    // toast提示Event
    var _toastEvent = MutableLiveData<String>()
    // toast提示Event,内容是资源文件
    var _toastIntEvent = MutableLiveData<Int>()
    // 不带参数的页面跳转Event
    var _pageNavigationEvent = MutableLiveData<Class<out Activity?>>()
    // 带参数的页面跳转,Event
    var _withGinsengNavigationEvent: MutableLiveData<PageJumpBase> = MutableLiveData<PageJumpBase>()
    // 关闭页面Event
    var _finishPageEvent = MutableLiveData<Boolean>()


    private lateinit var myApplication: MyApplication

    val viewId=BR.layout


    override fun onAny(owner: LifecycleOwner?, event: Lifecycle.Event?) {
        lifcycleOwner = owner
    }

    override fun onCreate() {
        myApplication = MyApplication.mInstance
    }

    override fun onStart() {}

    override fun onResume() {}

    override fun onPause() {}

    override fun onStop() {}

    override fun onDestroy() {}
}